import WrapFormItem from "components/wrap-form-item";
import React from "react";
import { messages } from "share/common";
import { Col, Row, Input, Select } from "antd";
const Option = Select.Option;

const hasValue = (value) => value && value.isRefBagCode;

const onChangeIsRefBagCode = (value, onChange) => {
  onChange({
    isRefBagCode: value,
    expBagCode: "",
  });
};

export default {
  id: "expBagCode",
  label: messages("expense-14.key270") /*关联发票袋*/,
  component: (
    <WrapFormItem parser={(value) => value || {}}>
      {(onChange, value) => {
        // console.log('value change', value)
        return (
          <Row gutter={10}>
            <Col span={10}>
              <Select
                style={{ width: "100%" }}
                onChange={(innerValue) => {
                  console.log("onChangeIsRefBagCode", innerValue, onChange);
                  onChangeIsRefBagCode(innerValue, onChange);
                }}
                value={value.isRefBagCode}
                placeholder={messages("common.select") /*请选择*/}
                getPopupContainer={(triggerNode) => triggerNode.parentNode}
              >
                <Option key="1001">{messages("common.yes") /*是*/}</Option>
                <Option key="1002">{messages("common.no") /*否*/}</Option>
              </Select>
            </Col>
            <Col span={14} style={{ height: 32 }}>
              <Input
                placeholder={messages("expense-14.key271") /*请输入编号*/}
                onChange={(e) => onChange({ expBagCode: e.target.value })}
                value={value.expBagCode}
                disabled={value.isRefBagCode !== "1001"}
              />
            </Col>
          </Row>
        );
      }}
    </WrapFormItem>
  ),
  hasValue,
  parser: (value) => {
    console.log("parser", value);
    return hasValue(value)
      ? {
          isRefBagCode: value.isRefBagCode === "1001",
          expBagCode: value.expBagCode,
        }
      : null;
  },
  tagParser: (value) => {
    return value.isRefBagCode === "1001" ? value.expBagCode || "是" : "否";
  },
};
